package com.java.admin.employeeInfo.controller;

import com.github.pagehelper.PageInfo;
import com.java.admin.employeeInfo.service.EmployeeService;
import com.java.database.entity.Employeeinfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    /**
     * 分页和模糊查询
     * @param keyword 模糊查询条件
     * @param pageNum  页码
     * @return
     */

    @RequestMapping("/queryEmployeeinfo")
    @ResponseBody
    public PageInfo queryEmployeeinfo(String keyword,String pageNum){
        PageInfo pageInfo = employeeService.queryEmployeeinfo(keyword, pageNum);
        return pageInfo;
    }

    /**
     * 添加
     * @param employeeinfo
     * @return
     */
    @RequestMapping("/addemplyee")
    public  String addemplyee(Employeeinfo employeeinfo){
        employeeService.addemployeeInfo(employeeinfo);
        return "redirect:/admin/employeeInfo.html";
    }
    /**
     * 删除
     */
    @RequestMapping("/deleteemplyee")
    public String deleteemplyee(String employeeid){
        System.out.println(employeeid);
        employeeService.daletemployeeInfo(employeeid);
        return "redirect:/admin/employeeInfo.html";
    }

    /**
     * 批量删除
     */
    @RequestMapping("/batchDeleteEmployee")
    public String batchDeleteEmployee(int [] employeeid){
        employeeService.batchDeleteEmployee(employeeid);
        return "redirect:/admin/employeeInfo.html";
    }

    /**
     * 修改
     */
    @RequestMapping("/updateemplyee")
    public String updateemplyee(Employeeinfo employeeinfo){
        employeeService.updatEmployeeid(employeeinfo);
        return "redirect:/admin/employeeInfo.html";
    }


    /**
     * 通过ID查询
     */
    @RequestMapping("/queryID")
    @ResponseBody
    public Employeeinfo queryID(String employeeid){
        Employeeinfo employeeinfo = employeeService.queryId(employeeid);
        return employeeinfo;
    }

    @RequestMapping("/queryEmployee")
    @ResponseBody
    public List<Employeeinfo> queryEmployee(){
        List<Employeeinfo> employeeinfos = employeeService.queryEmployee();
        return employeeinfos;
    }
}
